package cn.mysocketnet.a04udpdemo3;

import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class SendMessageDemo {
    public static void main(String[] args) {
        /*
            组播发送端代码
        */
        // https://blog.csdn.net/heromps/article/details/122920532
        // 多开实例配置
        //创建MulticastSocket对象
        try(MulticastSocket ms = new MulticastSocket()){
            // 创建DatagramPacket对象
            byte[] bytes = "你好,你好!".getBytes();
            InetAddress address = InetAddress.getByName("224.0.0.1");
            int port = 10000;
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length, address, port);
            // 调用MulticastSocket发送数据方法发送数据
            ms.send(dp);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
